﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PostSharp.Aspects;
using System.Reflection;

namespace EBookStore.AOP
{

    [Serializable]
    public class IntMinValue : OnMethodBoundaryAspect
    {
        public int Index { get; set; }
        public int MinValue { get; set; }
        
        

        

        public override void OnEntry(MethodExecutionArgs args)
        {
            Arguments a = args.Arguments;
            ParameterInfo[] pis = args.Method.GetParameters();
            
            
            if (Index >= 0)
            {
                if ((int)a[Index] < Convert.ToInt32(MinValue))
                {
                    throw new Exception(string.Format("Value {0} is below {1} value", a[Index], MinValue));
                }                                                    
            }
        }
    }
}
